<#include "../common/header.htm">
<div class="content-wrapper">
	<section class="content-header">
		<ol class="breadcrumb">
			<li><a href="${ctx}/">首页</a></li>
			<li class="active"><a href="${ctx}/cbbnotice/list">通知管理</a></li>
		</ol>
	</section>
	<section class="content">
		<div class="box">
			<form action="${ctx}/cbbnotice/list" method="POST" id="listForm">
				<div class="box-header">
					<div class="row RowSearchWork">
						<div class="col-sm-12">
							<div class="col-sm-2 special-style" style="width: 350px; padding-left: 90px;">
								<label>关键字：</label>
								<input name="keyword" type="text" class="form-control" value="${params.keyword!}" placeholder="请输入关键字" style="display: inline-block;width: 180px;margin-left: 5px;" />
							</div>
							<div class="col-sm-4" style="display: -webkit-box;">
								<label>发布时间：</label> 
				                <div class="input-group" style="margin-right: 100px;">
				                 	<input type="text" class="form-control" name="starTime" value="${params.starTime!}" id="starTime" autocomplete="off">
				                	<div class="input-group-addon">
				                    	<i>-</i>
				                  	</div>
				                 	<input type="text" class="form-control" name="endTime" value="${params.endTime!}" id="endTime" autocomplete="off">
				                </div>
							</div>
							<div class="col-sm-1">
								<input type="button" class="btn btn-default btn-search" onclick="channels.query();" value="查询" />
							</div>
							<div class="col-sm-1">
								<input type="button"  class="btn btn-primary" onclick="channels.form()" value="发布" />
							</div>
						</div>
					</div>
				</div>
				<div class="box-body">
					<table class="table table-hover table-bordered table-striped table-hide">
						<thead>
							<tr>
								<th width="3%">#</th>
								<th width="9%">标题</th>
								<th width="5%">内容</th>
								<th width="8%">提醒方式</th>
								<th width="6%">发布时间</th>
								<th width="8%">操作</th>
							</tr>
						</thead>
						<tbody>
							<#list page.content as u>
								<tr>
									<td>${page.size * page.number + u_index + 1}</td>
									<td>${u.title!}</td>
									<td>${u.content!}</td>
									<td>${u.loginRemind!}</td>
									<td>${u.addTime!}</td>
									<td>
										<a href="javascript:void(0)" onclick="channels.form('${u.channelId}')">撤销</a>
									</td>
								</tr>
							</#list>
						</tbody>
					</table>
					<#include "../common/page.htm">
				</div>
			</form>
		</div>
	</section>
</div>


<script type="text/javascript">
function DatePicker($beginSelector, $endSelector) {
	$beginSelector.datepicker({
		language : "zh-CN",
		autoclose : true,
		startView : 0,
		format : "yyyy-mm-dd",
		clearBtn : true,
		todayBtn : false,
		endDate : '${endTime!}'
	}).on('changeDate', function(ev) {
		if (ev.date) {
			$endSelector.datepicker('setStartDate', new Date(ev.date.valueOf()));
		} else {
			$endSelector.datepicker('setStartDate', null);
		}
	});
	
	$endSelector.datepicker({
		language : "zh-CN",
		autoclose : true,
		startView : 0,
		format : "yyyy-mm-dd",
		clearBtn : true,
		todayBtn : false,
		startDate : '${beginTime!}'
	}).on('changeDate', function(ev) {
		if (ev.date) {
			$beginSelector.datepicker('setEndDate', new Date(ev.date.valueOf()));
		} else {
			$beginSelector.datepicker('setEndDate', new Date());
		}
	});
}
// 仅选择日期
DatePicker($("#starTime"), $("#endTime"));
 

$('.select2').select2();
$.fn.modal.Constructor.prototype.enforceFocus = function() {};

var is_submit=false;

var channels = {
	query : function() {
		$(":input[name='pageNumber']").val(0);
		$("form").submit();
	},
	form : function(channelId) {
		if(is_submit){
			return;
		}
		is_submit=true;
		
		channelId = channelId ? channelId : "";
		var title = channelId ? "编辑通道" : "新增通道";
		
		var j = 0;
		base.getView({
			url:"${ctx}/channel/manageform?channelId="+channelId,
			success:function(result){
				bootbox.dialog({
					title:title,
					message:result,
					size:"large",
					closeButton : false,
					buttons:{
						cancel:{
							label:"取消",
							className:"btn btn-secondary",
							callback:function(){
								is_submit=false;
							}
						},
						sure:{
							label:"确定",
							className:"btn btn-primary",
							callback:function() {
								if (j != 0) {
									is_submit=false;
									return ;
								}
								j++;
								base.validAndAjaxSubmitJson($("#addChannel"), function () {
									j = 0;
								}, function (data) {
									if (data.result == 'success') {
										$("#listForm").submit();
									} else {
										j = 0;
									}
								});
								return false;
							}
						}
					}
				})
			}
		});
	},
	extension : function (channelId) {
		// console.log("channelId="+channelId);
		if(is_submit){
			return;
		}
		is_submit=true;
		channelId = channelId ? channelId : "";
		var title = "通道延期";
		var j = 0;
		base.getView({
			url:"${ctx}/channel/manageExtension?channelId="+channelId,
			success:function(result){
				bootbox.dialog({
					title:title,
					message:result,
					size:"large",
					closeButton : false,
					buttons:{
						cancel:{
							label:"取消",
							className:"btn btn-secondary",
							callback:function(){
								is_submit=false;
							}
						},
						sure:{
							label:"确定",
							className:"btn btn-primary",
							callback:function() {
								if (j != 0) {
									is_submit=false;
									return ;
								}
								j++;
								/* base.validAndAjaxSubmit($("#extensionChannel"), $("#listForm"), function () {
									j = 0;
								}); */
								base.validAndAjaxSubmitJson($("#extensionChannel"), function () {
									j = 0;
								}, function (data) {
									if (data.result == 'success') {
										$("#listForm").submit();
									} else {
										j = 0;
									}
								});
								return false;
							}
						}
					}
				})
			}
		});
	}
}
</script>
<#include "../common/footer.htm">